<template>
    <div id="app">
  <div v-if="showLoginModal" class="modal-overlay">
    <div class="modal-content">
      <h2>登录</h2>
      <form @submit.prevent="handleLogin">
        <div>
          <label for="username">Admin</label>
          <input type="text" id="username" v-model="username" required placeholder="请输入账号" />
        </div>
        <div>
          <label for="password">密码</label>
          <input type="password" id="password" v-model="password" required placeholder="请输入密码" />
        </div>
        <div>
          <button type="submit" @click="AdminLog">登录</button>
          <button type="button" @click="showLoginModal = false" class="close-btn">关闭</button>
        </div>
      </form>
    </div>
  </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';
const router =useRouter()
const showLoginModal = ref(true);
const username = ref('');
const password = ref('');
function AdminLog(){
    if(username.value=='zzq'&&password.value==123){
        router.push({path:'admin'})
    }
    else{
        alert("用户名或密码错误！")
        router.push({path:'/'})
    }
}
const handleLogin = () => {
  showLoginModal.value = false; // 登录后关闭弹窗
};
</script>

<style scoped>
/* 背景图及渐变 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 999;
  animation: fadeIn 0.3s ease-in-out;
}

/* 弹窗内容 */
.modal-content {
  background: rgba(0, 0, 0, 0.6) url('https://img.pptjia.com/image/cj/2018022816/2016021610201649.jpg') center/cover no-repeat;
  padding: 30px;
  border-radius: 12px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
  text-align: center;
  animation: slideUp 0.3s ease-out;
}

h2 {
  font-size: 24px;
  margin-bottom: 20px;
  color: #333;
}

/* 输入框样式 */
input {
  width: 100%;
  padding: 12px;
  margin-bottom: 15px;
  border-radius: 8px;
  border: 1px solid #ccc;
  box-sizing: border-box;
  font-size: 16px;
  transition: border-color 0.3s ease;
}

input:focus {
  border-color: #007bff;
  outline: none;
}

/* 按钮样式 */
button {
  width: 100%;
  padding: 12px;
  margin-top: 10px;
  border-radius: 8px;
  background-color: #007bff;
  color: white;
  border: none;
  font-size: 16px;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

button:hover {
  background-color: #0056b3;
}

button.close-btn {
  background-color: #dc3545;
}

button.close-btn:hover {
  background-color: #c82333;
}

/* 动画效果 */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    transform: translateY(30px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}
</style>